﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MpSoft.Library.BUSS.Contents;
using MpSoft.Library.BUSS.Categories;
using MpSoft.Basic.Utils;

namespace MpSoft.Web.Controls.News
{
    public partial class NewsControl : System.Web.UI.UserControl
    {
        #region Var

        private int ItemID = 0;
        private string CategorySeName = string.Empty;
        private Library.DTO.Category category = null;
        #endregion

        #region Method

        private void BindControl()
        {
            if (category == null)
                category = CategoryBUSS.Category_BySeName(CategorySeName);
        }
        private void News(int pageindex)
        {
            BindControl();
            int TotalRow;
            MpPage.PageSize = 15;
            var list = NewsBUSS.News_AllPaged(category.CategoryID, 1, 1, null, 1, MpPage.PageSize, out TotalRow);
            rpNews.DataSource = list;
            rpNews.DataBind();
            MpPage.ItemCount = TotalRow;
            
        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ItemID"] != null)
                int.TryParse(Request.QueryString["ItemID"].ToString(), out ItemID);
            if (Request.QueryString["CategoryCode"] != null)
                CategorySeName = Request.QueryString["CategoryCode"].ToString();
            News(1);
        }

        protected void MpPage_Command(object sender, CommandEventArgs e)
        {

            int pageindex;
            int.TryParse(e.CommandArgument.ToString(), out pageindex);
            MpPage.CurrentIndex = pageindex;
            News(pageindex);
            
        }

        #endregion
      

        #region Properties
        #endregion
    }
}